package com.pretty.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.problem.dto.ProblemPageDTO;
import com.pretty.test.controller.pets.problem.vo.ProblemPageVO;
import com.pretty.test.controller.pets.problem.wrapper.ProblemPageWrapper;
import com.pretty.test.entity.PetsProblem;
import com.pretty.test.mapper.PetsProblemMapper;
import com.pretty.test.service.IPetsProblemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pretty.test.utils.otherutils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 常见问题服务实现类
 * @author dujianyu
 * @since 2021-04-09
 */
@Service
public class PetsProblemServiceImpl extends ServiceImpl<PetsProblemMapper, PetsProblem> implements IPetsProblemService {

    @Override
    public IPage<ProblemPageVO> selectProblemPage(Page<PetsProblem> page, ProblemPageDTO dto) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getProblem()),"problem",dto.getProblem());
        queryWrapper.lt(!Func.isEmpty(dto.getCreateTimeEnd()),"create_time",dto.getCreateTimeEnd());
        queryWrapper.gt(!Func.isEmpty(dto.getCreateTimeStart()),"create_time",dto.getCreateTimeStart());
        queryWrapper.orderByDesc("update_time");
        return ProblemPageWrapper.build().pageVO(baseMapper.selectPage(page,queryWrapper));
    }

    @Override
    public List<ProblemPageVO> selectProblemList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        queryWrapper.orderByDesc("update_time");
        return ProblemPageWrapper.build().listVO(baseMapper.selectList(queryWrapper));
    }
}
